/*
 * @Author: your name
 * @Date: 2021-04-17 15:05:12
 * @LastEditTime: 2021-06-07 16:03:06
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \egg-demo\app\controller\auth.js
 */
'use strict';

const { Controller } = require('egg');

class AuthController extends Controller { 
  async login() {
    const { ctx } = this;
    try {
      const token = await ctx.service.auth.login(this);
      ctx.helper.renderSuccess( ctx, { message: '请求成功', data: { token }})
    } catch(err) {
      ctx.helper.renderFail( ctx, { message: err, data: err });
    }
  }

  async checkLogin() {
    const { ctx } = this;
    try {
      const loginUser = await ctx.service.auth.checkLogin(this);
      ctx.helper.renderSuccess( ctx, { data: loginUser });
    }catch (err) {
      ctx.helper.renderFail( ctx, { message: err, data: err} )
    }
  }
}

module.exports = AuthController;